Vue.component('update', {
    template: `
		<el-dialog title="修改" width="600px" class="icon-dialog" :visible.sync="show" @open="open" :before-close="closeForm" append-to-body>
			<el-form :size="size" ref="form" :model="form" :rules="rules" :label-width=" ismobile()?'90px':'16%'">
				<el-row >
					<el-col :span="24">
						<el-form-item label="分类标题" prop="title">
							<el-input  v-model="form.title" autoComplete="off" clearable  placeholder="请输入用户名"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="分类标题(英语)" prop="e_title">
							<el-input  v-model="form.e_title" autoComplete="off" clearable  placeholder="请输入分类标题(英语)"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="分类标题(繁体)" prop="t_title">
							<el-input  v-model="form.t_title" autoComplete="off" clearable  placeholder="请输入分类标题(繁体)"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="分类图片(简体)" prop="pic">
							<Upload v-if="show" size="small" file_type="image" :image.sync="form.pic"></Upload>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="分类图片(英语)" prop="e_pic">
							<Upload v-if="show" size="small"      file_type="image" :image.sync="form.e_pic"></Upload>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="分类图片(繁体)" prop="t_pic">
							<Upload v-if="show" size="small"      file_type="image" :image.sync="form.t_pic"></Upload>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button :size="size" :loading="loading" type="primary" @click="submit" >
					<span v-if="!loading">确 定</span>
					<span v-else>提 交 中...</span>
				</el-button>
				<el-button :size="size" @click="closeForm">取 消</el-button>
			</div>
		</el-dialog>
	`,
    components:{
    },
    props: {
        show: {
            type: Boolean,
            default: false
        },
        size: {
            type: String,
            default: 'small'
        },
        info: {
            type: Object,
        },
    },
    data(){
        return {
            form: {
                title:'',
                e_title:'',
                t_title:'',
                pic:'',
                t_pic:'',
                e_pic:'',
            },
            loading:false,
            rules: {

            }
        }
    },
    methods: {
        open(){
            this.form = this.info
            this.form.create_time = parseTime(this.form.create_time)
        },
        submit(){
            this.$refs['form'].validate(valid => {
                if(valid) {
                    this.loading = true
                    axios.post(base_url + '/Charitable/edit',this.form).then(res => {
                        if(res.data.status == 200){
                            this.$message({message: res.data.msg, type: 'success'})
                            this.$emit('refesh_list')
                            this.closeForm()
                        }else{
                            this.loading = false
                            this.$message.error(res.data.msg)
                        }
                    }).catch(()=>{
                        this.loading = false
                    })
                }
            })
        },
        closeForm(){
            this.$emit('update:show', false)
            this.loading = false
            if (this.$refs['form']!==undefined) {
                this.$refs['form'].resetFields()
            }
        },
    }
})
